﻿using System;
using Wintellect.Sterling;

namespace Caramel.Sterling
{
	public class SterlingUnitOfWork : IUnitOfWork
	{
		private bool _isDisposed = false;

		public SterlingUnitOfWork(ISterlingDatabaseInstance databaseInstance, string name)
		{
			this.DatabaseInstance = databaseInstance;
			this.Name = name;
			this.ID = Guid.NewGuid();
		}

		public ISterlingDatabaseInstance DatabaseInstance { get; set; }

		public string Name { get; private set; }

		public Guid ID { get; private set; }

		public bool WasCommitted { get; private set; }

		public bool WasRolledBack { get; private set; }

		public void Commit()
		{
			throw new NotImplementedException();
		}

		public void Rollback()
		{
			throw new NotImplementedException();
		}

		public void Evict(object entity)
		{
			throw new NotImplementedException();
		}

		public void Dispose()
		{
			if (!_isDisposed)
			{
				//if (_transaction.IsActive)
				//{
				//    this.Rollback();
				//}

				//_transaction = null;
				//this.Session.Dispose();
				//this.Session = null;

				UnitOfWork.DisposeOfUnitOfWork(this);

				_isDisposed = true;
			}
		}
	}
}
